<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="msg"></div>
    <script>
      const xhr = new XMLHttpRequest();
      xhr.open("GET", "http://127.0.0.1:8081/tours ");
      // xhr.timeout = 1000; //超时
      xhr.timeout = Math.random() * 10000; //超时
      console.log(xhr.timeout);
      xhr.onload = function () {
        console.log(xhr.response);
      };
      xhr.ontimeout = function () {
        // console.log("ontimeout");
        msg.innerHTML = `请求超时<a href="./7.html">刷新</a>`;
      };
      xhr.send();
    </script>
  </body>
</html>
